/**游戏绘图
 * @date   2011-4-9
 * @author tianye
 */
package cn.edu.dlut.WingGame.Game;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLSurfaceView.Renderer;
import cn.edu.dlut.WingGame.Graphic.GLDevice;
import cn.edu.dlut.WingGame.Tools.FPSCounter;
import cn.edu.dlut.WingGame.Tools.TimeCounter;

public class WingRender implements Renderer {
	FPSCounter fps;
	private TimeCounter timer;

	public WingRender(WingActivity activity) {
		fps = new FPSCounter();
	}

	public void setFPS(int fps) {
		timer = new TimeCounter();
		timer.setInterval(1000.0f / fps);
		timer.restartTimer();
	}

	public void onDrawFrame(GL10 gl) {
		if (WingGame.isRenderFPS()) {
			while (!timer.checkTimer())
				;
			timer.restartTimer();
		}
		GLDevice.onDrawFrame(gl);
		WingGame.render();
		if (WingGame.isShowFPS()) {
			fps.nextFrame();
			fps.drawFPS();
		}
	}

	public void onSurfaceChanged(GL10 gl, int width, int height) {
		GLDevice.onSurfaceChanged(gl, width, height);

	}

	public void onSurfaceCreated(GL10 gl, EGLConfig config) {
		GLDevice.onSurfaceCreated(gl, config);
	}

}
